class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def smallestFromLeaf(self, root):
        """
        :type root: TreeNode
        :rtype: str
        """
        out = []
        self.min_v = None

        def search(node):
            out.append(chr(node.val + ord('a')))
            if not node.left and not node.right:
                if not self.min_v:
                    self.min_v = ''.join(out[::-1])
                else:
                    self.min_v = min(self.min_v, ''.join(out[::-1]))
            else:
                if node.left:
                    search(node.left)
                if node.right:
                    search(node.right)
            out.pop()

        search(root)
        return self.min_v
